$(function(){

    //品牌荣誉
    var brandHistory ={

    };

    /**获取当前品牌历史信息列表**/
    brandHistory.init = function (){
        $.ajax({
            async: false,
            url: '/brand/findBrandHistory',
            data: {},
            success: function (result) {
                var brandList = result.data;
                //获取需要渲染的列表
                var $historyDiv = $(".history-content");
                if( brandList !=null){
                    var itemHtml ='';
                    //循环获取品牌信息
                    $.each(brandList,function(key,brand){
                        itemHtml +='<div class="history-item">';
                        itemHtml +='<div class="history-message" style="display: none;">'+brand.brandText+'</div>';
                        var yearName = brand.releaseTime.substring(0,brand.releaseTime.indexOf("-"));
                        itemHtml +='<a title="'+brand.brandName+'" ' +
                            'year="'+yearName+'"><img src="'+brand.url+'">';
                        if(key%4==0){
                            itemHtml +='<div class="item-icon tr"><span>'+yearName+'</span></div>';
                        }else if( key%3==0){
                            itemHtml +='<div class="item-icon bl"><span>'+yearName+'</span></div>';
                        }else if( key%2==0){
                            itemHtml +='<div class="item-icon br"><span>'+yearName+'</span></div>';
                        }else{
                            itemHtml +='<div class="item-icon tl"><span>'+yearName+'</span></div>';
                        }
                        itemHtml +='<div class="item-year"><h2>'+brand.releaseTime.substring(0,brand.releaseTime.indexOf("-"))+'</h2>' +
                            '<div>'+brand.brandText+'</div></div>';

                        itemHtml +='</a></div>';
                    });
                    $historyDiv.empty().append(itemHtml);

                    $('.history-item a').bind('mouseover',function(){
                        $(this).find(".item-icon").addClass("icon-100");
                        $(this).find(".item-year").css("opacity","0.75");
                        $(this).find(".item-icon>span").css("opacity","0");
                    });

                    $('.history-item a').bind('mouseout',function(){
                        $(this).find(".item-icon").removeClass("icon-100");
                        $(this).find(".item-year").css("opacity","0");
                        $(this).find(".item-icon>span").css("opacity","1");
                    });

                    //绑定图片切换事件
                    $('.history-content').on("click",'.history-item',function(){
                        var this_ = $(this);
                        var images = this_.parents('.history-content').find('.history-item');
                        var imagesArr = new Array(),yearsArr =new Array(),messageArr = new Array();
                        $.each(images, function (i, image) {
                            imagesArr.push($(image).find('img').attr('src'));
                            yearsArr.push($(image).find('a').attr('year'));
                            messageArr.push($(image).find('.history-message').text());
                        });
                        $.pictureViewer({
                            images: imagesArr, //需要查看的图片，数据类型为数组
                            yearsArr: yearsArr,
                            messageArr : messageArr,
                            initImageIndex: this_.index() + 1, //初始查看第几张图片，默认1
                            scrollSwitch: true //是否使用鼠标滚轮切换图片，默认false
                        });
                    });
                }
            }
        });
    }
    //初始化
    brandHistory.init();
    header.selLiCss("brand");
    //面包屑名称
    $("#menu-ico span").html("•&nbsp;&nbsp;品牌&nbsp;&nbsp;•&nbsp;&nbsp;品牌历史");
});